﻿using B.S.Traceability.Domain;
using B.S.Traceability.Error;
using B.S.Traceability.Infrastructure.Interface;
using B.S.Traceability.Read.API.Application.Commends.IntegrateImg;
using MediatR;

namespace B.S.Traceability.Read.API.Application.CommendHandlers.IntegrateImg
{


    public class GetDynamicImgCommendHandlers : IRequestHandler<GetDynamicImgCommends, APIResult<List<IntegrateImgs>>>
    {

        private readonly IBaseRepository<IntegrateImgs> IntegrateImgsRepository;

        public GetDynamicImgCommendHandlers(IBaseRepository<IntegrateImgs> integrateImgsRepository)
        {
            IntegrateImgsRepository = integrateImgsRepository;
        }



        /// <summary>
        /// 获取动检图片信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<List<IntegrateImgs>>> Handle(GetDynamicImgCommends request, CancellationToken cancellationToken)
        {
            APIResult<List<IntegrateImgs>> result = new APIResult<List<IntegrateImgs>>();
            result.Code = APIEnum.查询成功;
            result.Msg = "查询成功";

            var list = IntegrateImgsRepository.GetAll().Where(p => p.BatchId == request.BatchId && p.IsDel == false);
            if (!string.IsNullOrEmpty(request.ImgName))
            {
                list = list.Where(p => p.ImgName.Contains(request.ImgName));
            }
            else
            {
                list = list.Where(p => p.ImgName.Contains(""));
            }
            result.data = list.ToList();
            return await Task.FromResult(result);
        }
    }
}
